package com.max.rabbitmq.learn.direct;

import com.max.rabbitmq.learn.util.ConnectionUtil;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
import java.util.concurrent.TimeoutException;

/**
 * @description 静态路由模式发送者
 * @author yandong
 * @create 2021年4月07日 10:25:23
 */
public class Send {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();

        channel.exchangeDeclare("exchange.max.direct", BuiltinExchangeType.DIRECT, true);
        String message = "hello world";
        channel.basicPublish("exchange.max.direct", "error", new AMQP.BasicProperties().builder().messageId(UUID.randomUUID().toString()).build(),message.getBytes(StandardCharsets.UTF_8));
        channel.basicPublish("exchange.max.direct", "info", new AMQP.BasicProperties().builder().messageId(UUID.randomUUID().toString()).build(),message.getBytes(StandardCharsets.UTF_8));
        channel.basicPublish("exchange.max.direct", "warn", new AMQP.BasicProperties().builder().messageId(UUID.randomUUID().toString()).build(),message.getBytes(StandardCharsets.UTF_8));
        channel.close();
        connection.close();
    }
}
